<%@ page language="java" contentType="text/html; charset=UTF-8"
		 pageEncoding="UTF-8"%>
<%@ page isELIgnored ="false" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<%--	<link rel="stylesheet" type="text/css" href="../css/easyui/default/easyui.css">--%>
<%--	<link rel="stylesheet" type="text/css" href="../css/easyui/icon.css">--%>
	<script src="https://www.jq22.com/jquery/jquery-1.10.2.js"></script>
	<style>
		.formCenter {
			background-color: #f4fcff;
			/*width: 80%;*/
			/*margin: 0 auto;*/
			border: solid 1px #3C3F41
		}
		.buttonClass {
			width: 150px;
			height: 50px;
			background-color: #62beee;
		}
		.tdClass {
			font-weight: bold;
		}
	</style>
</head>
<body>

	<c:if test="${empty requestScope.zhulis}">
		没有任何助力信息。
	</c:if>
	<c:if test="${!empty requestScope.zhulis}">
		<table border="1" cellpadding="10" cellspacing="0" class="formCenter">
			<tr>
				<td colspan="11">
					<input type="button" onclick="qingchu()" value="清除" class="buttonClass">
				</td>
			</tr>
			<tr style="text-align: center;font-weight: bold">
				<td hidden>ID</td>
				<td>用户名</td>
				<td>等级</td>
				<td>助力1</td>
				<td>助力2</td>
				<td>助力3</td>
				<td>助力4</td>
				<td>助力5</td>
				<td>助力6</td>
				<td>备注</td>
				<td>操作</td>
			</tr>
			<c:forEach items="${requestScope.zhulis}" var="emp">
				<tr class="trclass">
					<td hidden>${emp.id}</td>
					<td>${emp.user}</td>
					<td class="tdClass">${emp.dengji}</td>
					<td>${emp.zhuli1}</td>
					<td>${emp.zhuli2}</td>
					<td>${emp.zhuli3}</td>
					<td>${emp.zhuli4}</td>
					<td>${emp.zhuli5}</td>
					<td>${emp.zhuli6}</td>
					<td>${emp.bz}</td>
					<td><a href="javascript:;" onclick="yuliu(${emp.id})">预留</a>&nbsp;&nbsp;
						<a href="javascript:;" onclick="zhulijia(${emp.id})">助力</a>&nbsp;&nbsp;
						<a href="javascript:;" onclick="zhulijian(${emp.id})">退回</a>&nbsp;&nbsp;
						<a href="javascript:;" onclick="edit(${emp.id})">编辑</a></td>
				</tr>
			</c:forEach>
		</table>
	</c:if>
</body>
<script>
	function qingchu() {
		$.ajax({
			url: "/gailou/qingchu", async: true,
			success: function (data) {
				if("true"==data){
					alert("操作成功！");
					location.reload();
				}else {
					alert("操作失败！");
				}
			}
		});
	}
	function edit(id){
		var message = prompt("请输入修改信息：(格式为'等级-助力次数-预留内容')");
		console.log(message);
		if(message=='' || message==null || message==undefined){
			return;
		}
		var params = message.split("-");
		console.log(params);
		if(params.length!=3){
			return;
		}
		var dengji = params[0];
		var cishu = params[1];
		var yuliuMessage = params[2];
		$.ajax({
			url: "/gailou/yuliu", async: true,
			data:{"id":id,"yuliuMessage":yuliuMessage,"cishu":cishu,"dengji":dengji},
			success: function (data) {
				console.log(data);
				if("true"==data){
					alert("操作成功！");
					location.reload();
				}else {
					alert("操作失败！");
				}
			}
		});
	}
	function zhulijia(id) {
		$.ajax({
			url: "/gailou/yuliu", async: true, data:{"id":id,"yuliuMessage":1}, success: function (data) {
				console.log(data);
				if("true"==data){
					location.reload();
				}else {
					alert("助力次数上限");
				}
			}
		});
	}
	function zhulijian(id) {
		$.ajax({
			url: "/gailou/zhulijian", async: true, data:{"id":id}, success: function (data) {
				console.log(data);
				if("true"==data){
					location.reload();
				}else {
					alert("异常，请检查是否存在回退情况");
				}
			}
		});
	}
	function yuliu(id) {
		var message = prompt("请输入预留信息：");
		console.log(message);
		if(message=='' || message==null || message==undefined){
			return;
		}
		$.ajax({
			url: "/gailou/yuliu", async: true, data:{"id":id,"yuliuMessage":message}, success: function (data) {
				console.log(data);
				if("true"==data){
					location.reload();
				}else {
					alert("助力次数上限");
				}
			}
		});
	}
	// $(function () {
	// 	$(".trclass").click(function () {
	// 		console.log(11);
	// 	})
	// })
</script>
</html>